package com.ctgu.springboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctgu.springboot.common.QueryPageParam;
import com.ctgu.springboot.entity.PubResouse;
import com.ctgu.springboot.mapper.SubmitResouseMapper;
import com.ctgu.springboot.entity.SubmitResouse;
import com.ctgu.springboot.service.SubmitResouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cs
 * @since 2023-07-07
 */
@Service
public class SubmitResouseServiceImpl extends ServiceImpl<SubmitResouseMapper, SubmitResouse> implements SubmitResouseService {

    @Autowired
    private SubmitResouseMapper submitResouseMapper;

    @Override
    public IPage<SubmitResouse> listPage(QueryPageParam query) {
        Integer id = (Integer) query.getParam().get("sub_id");
        String name = (String) query.getParam().get("sub_name");
        String stuName = (String) query.getParam().get("stu_name");
        String teamName = (String) query.getParam().get("team_name");

        Page<SubmitResouse> page = new Page<>();
        page.setCurrent(query.getPageNum());
        page.setSize(query.getPageSize());

        LambdaQueryWrapper<SubmitResouse> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (id!=null) {
            lambdaQueryWrapper.like(SubmitResouse::getSubId, id);
        }
        if (StringUtils.isNotBlank(name) && !"null".equals(name)) {
            lambdaQueryWrapper.like(SubmitResouse::getSubName, name);
        }
        if (StringUtils.isNotBlank(stuName) && !"null".equals(stuName)) {
            lambdaQueryWrapper.like(SubmitResouse::getStuName, stuName);
        }
        if (StringUtils.isNotBlank(teamName) && !"null".equals(teamName)) {
            lambdaQueryWrapper.like(SubmitResouse::getTeamName, teamName);
        }
        return submitResouseMapper.listPage(page, lambdaQueryWrapper);
    }

    public SubmitResouse selectByUrl(String url){
        return submitResouseMapper.selectByUrl(url);
    }
}
